package org.jeecg.modules.cosmetic.model.vo;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
import org.jeecgframework.poi.excel.annotation.ExcelVerify;
import org.jeecgframework.poi.excel.entity.params.ExcelVerifyEntity;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.text.NumberFormat;

/**
 * @author scx
 * @date 2022/7/1 10:50 上午
 */
@Data
public class FormulaExcelVO {

    private static NumberFormat numberFormat = NumberFormat.getInstance();

    static {
        numberFormat.setGroupingUsed(false);
        //设置小数点保留十位
        numberFormat.setMaximumFractionDigits(10);
    }


    /**
     * 序号
     */
    @Excel(name = "序号")
    private Integer idxNum;

    /**
     * 标准中文名称
     */
    @Excel(name = "标准中文名称")
    @NotBlank(message = "标准中文名称不能为空")
    private String cnName;

    /**
     * 英文名称
     */
    @Excel(name = "INCI名称/英文名称")
    @NotBlank
    private String incicName;

    /**
     * 原料含量百分比
     */
    @Excel(name = "原料含量(%)", importConvert = true)
    private String materialContent;

    /**
     * 原料成分含量百分比
     */
    @Excel(name = "原料中成分含量(%)", importConvert = true)
    private String ingredientContent;

    /**
     * 实际成分含量百分比
     */
    @Excel(name = "实际成分含量(%)", importConvert = true)
    @NotBlank(message = "实际成分含量不能为空")
    private String actualContent;

    /**
     * 主要使用目的
     */
    @Excel(name = "主要使用目的")
    private String majorUsePurpose;

    //重写set方法，前面加convert,配合importConvert注解
    public void convertsetMaterialContent(String materialContent) {
        if (StringUtils.isNotEmpty(materialContent)) {
            BigDecimal bigMaterialContent = new BigDecimal(materialContent);
            this.materialContent = numberFormat.format(bigMaterialContent);
        }
    }

    public void convertsetIngredientContent(String ingredientContent) {
        if (StringUtils.isNotEmpty(ingredientContent)) {
            BigDecimal bigIngredientContent = new BigDecimal(ingredientContent);
            this.ingredientContent = numberFormat.format(bigIngredientContent);
        }
    }

    public void convertsetActualContent(String actualContent) {
        if (StringUtils.isNotEmpty(actualContent)) {
            BigDecimal bigActualContent = new BigDecimal(actualContent);
            this.actualContent = numberFormat.format(bigActualContent);
        }
    }
}
